<?php 
//框架第一次执行的类
class Hd{
	public static function run(){
		//如果Application没有的时候
		if(!is_dir('Application')){
			//创建文件夹
			self::_makeDir();
			//复制文件
			self::_copyFile();
		}
		//载入核心文件
		self::_loadCore();
		//执行应用类
		App::run();
	}
	/**
	 * 载入核心文件
	 */
	private static function _loadCore(){
		$coreFile = array(
			'Hdphp/Library/Functions.php',
			'Hdphp/Org/Smarty/Smarty.class.php',
			'Hdphp/Library/SmartyView.class.php',
			'Hdphp/Library/App.class.php',
			'Hdphp/Library/Controller.class.php',
		);
		foreach ($coreFile as $f) {
			require_once $f;
		}
	}
	
	/**
	 * 复制文件，都是从Common文件夹复制出来的
	 */
	private static function _copyFile(){
		//复制控制器
		copy('Hdphp/Common/IndexController.class.php', 'Application/Home/Controller/IndexController.class.php');
		//复制成功和失败的模板
		copy('Hdphp/Common/success.php', 'Public/success.php');
		copy('Hdphp/Common/error.php', 'Public/error.php');
		//复制默认欢迎界面模板
		copy('Hdphp/Common/index.php', 'Application/Home/View/Index/index.php');
		//复制配置项到默认用户应用
		copy('Hdphp/Common/config.php', 'Application/Home/Conf/config.php');
		//复制配置项到公共应用
		copy('Hdphp/Common/config.php', 'Application/Common/Conf/config.php');
	}
	
	/**
	 * 创建文件夹
	 */
	private static function _makeDir(){
		$dirArr = array(
			'Application/Home',
			'Application/Home/Controller',
			'Application/Home/View',
			'Application/Home/View/Index',
			'Application/Home/Conf',
			'Application/Common',
			'Application/Common/Conf',
			'Public'
		);
		
		foreach ($dirArr as $d) {
			is_dir($d) || mkdir($d,0777,true);
		}
		
	}
	
}
Hd::run();

 ?>